package channelService

import (
	"errors"
	"gitee.com/fierce_wolf/go-fox-edge-channel-common/channelLogger"
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedisRpc"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Hex"
	"net"
)

type publishShervice struct {
}

func (e *publishShervice) publish(ctx net.Conn, requestVO *commRedisRpc.ChannelRequestVO) error {
	if requestVO.Send == nil || requestVO.Send == "" {
		return errors.New("发送数据不能为空！")
	}

	// 格式转换
	send := Hex.DecodeString(requestVO.Send)

	// 发送数据
	_, err := ctx.Write(send)
	if err != nil {
		return err
	}

	// 打印日志
	channelLogger.PrintChannelDebugLogger(requestVO.Name, "发送", requestVO.Send.(string))

	return nil
}
